<template>
  <div class="user">
    <div class="userprofiles" v-for="item in userprofiles" :key="item.id" @click="toUserInfoPage(item.userId)">
      <div class="left">
        <img :src="item.avatarUrl" />
        <span class="name">{{ item.nickname }}</span>
        <span class="iconfont icon-sexm" v-if="item.gender === 1"></span>
        <span class="iconfont icon-sexw" v-if="item.gender === 2"></span>
      </div>
      <span class="detailDescription">{{item.detailDescription }}</span>
    </div>
  </div>
</template>

<script>
import { getCloudSearch } from '../../network/search.js'
export default {
  props: ['type', 'value'],
  data () {
    return {
      userprofiles: [],
      userprofileCount: 0
    }
  },
  methods: {
    toUserInfoPage (id) {
      this.$router.push('/user_info/' + id)
    },
    getCloudSearch (type, keywords) {
      getCloudSearch(type, keywords).then(res => {
        // console.log(res.data)
        this.userprofiles = res.data.result.userprofiles
        this.userprofileCount = res.data.result.userprofileCount
        this.$emit('singerCount', this.userprofileCount + ' 位用户')
        // console.log(this.userprofiles)
      })
    }
  },
  created () {
    this.getCloudSearch(this.type, this.value)
  },
  watch: {
    value (newVal, oldVal) {
      // console.log('新关键词:' + newVal)
      this.value = newVal
      this.getCloudSearch(this.type, this.value)
    }
  }
}
</script>

<style lang="less" scoped>
  .userprofiles {
    width: 100%;
    padding: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    .left {
      display: flex;
      flex-direction: row;
      align-items: center;
      width: 50%;
      img {
        width: 75px;
        height: 75px;
        border-radius: 50%;
        margin-right: 15px;
      }
    }
    .detailDescription {
      margin-right: 30px;
      color: #9d9d9d;
    }
  }
  .userprofiles:nth-child(2n) {
    background-color: #f9f9f9;
  }
  .userprofiles:hover {
    background-color: #f0f1f2;
  }
  .icon-sexm, .icon-sexw {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    padding: 2px;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .icon-sexm {
    color: #6dbde0;
    background-color: #b5e9f6;
  }
  .icon-sexw {
    color: #e85792;
    background-color: #f4c3df;
  }
</style>
